package com.xiaomei.manager.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xiaomei.manager.dao.TRecommendIndexMapper;
import com.xiaomei.manager.model.TRecommendIndex;
import com.xiaomei.manager.model.TRecommendIndexExample;
import com.xiaomei.manager.model.UserAndRecommandDto;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaomei.manager.dao.UserMapper;
import com.xiaomei.manager.model.User;
import com.xiaomei.manager.service.IUserService;
import com.xiaomei.manager.web.dto.CountDto;
import com.xiaomei.manager.web.dto.OrderAndUser;
import com.xiaomei.manager.web.dto.UserAndCompleteDto;
import com.xiaomei.manager.web.dto.UserAndDriverAuthDto;
import com.xiaomei.manager.web.dto.req.FemaleDto;
import com.xiaomei.manager.web.dto.req.UserCompleteDto;
import com.xiaomei.manager.web.dto.req.UserQueryDto;
import com.xiaomei.manager.web.page.Page;

@Service
public class UserServiceImpl implements IUserService{
	
	@Autowired
	private UserMapper userMapper;

	@Autowired
	private TRecommendIndexMapper recommendIndexMapper;
	
	@Override
	public List<OrderAndUser> selectInviteUserByOrderCode(String mobile) {
		// TODO 自动生成的方法存根
		return userMapper.selectInviteUserByOrderCode(mobile);
	}

	@Override
	public List<OrderAndUser> selectAll() {
		// TODO 自动生成的方法存根
		return userMapper.selectAll();
	}

	@Override
	public List<UserAndDriverAuthDto> getselectList(UserQueryDto dto, Page<UserAndDriverAuthDto> page) {
		// TODO 自动生成的方法存根
		page.setParamDto(dto);
		return userMapper.selectByParamMap(page);
	}
	
	@Override
	public Object selectByPrimaryKey(Integer id) {
		// TODO 自动生成的方法存根
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public Object selectByUserCode(String userCode) {
		return userMapper.selectByUserCode(userCode);
	}
	/**
	 * 每日女乘客注册量
	 */
	@Override
	public List<FemaleDto> getFemale(Page<FemaleDto> page) {
		// TODO Auto-generated method stub
		return userMapper.selectFemale(page);
	}
	/**
	 * 所有用户的成交单数

	 */
	@Override
	public List<UserCompleteDto> getUserComplete(UserAndCompleteDto dto,
			Page<UserCompleteDto> page) {
		// TODO Auto-generated method stub
		page.setParamDto(dto);
		return userMapper.selectUserComplete(page);
	}

	@Override
	public List<User> selectFictitiousUser() {
		// TODO Auto-generated method stub
		return userMapper.selectFictitiousUser();
	}

	@Override
	public CountDto selectCount() {
		// TODO Auto-generated method stub
		return userMapper.selectCount();
	}

	@Override
	public List<FemaleDto> selectFemaleCount(String startTime, String endTime,
			String sex) {
		// TODO Auto-generated method stub
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		map.put("sex", sex);
		return userMapper.selectFemaleCount(map);
	}

	@Override
	public List<UserAndRecommandDto> getUserRecommandValue(UserQueryDto dto, Page<UserAndRecommandDto> page) {
		page.setParamDto(dto);
		return userMapper.selectUserCecommandValue(page);
	}

	public boolean updateUserRecommend(String userCode, Integer value) {
		TRecommendIndex rec = new TRecommendIndex();
		rec.setUserCode(userCode);
		rec.setRecommendValue(value>200? 200:value);
		return recommendIndexMapper.updateByPrimaryKey(rec) > 0;
	}

	@Override
	public boolean insertUser(User user) {
		// TODO Auto-generated method stub
		return userMapper.insertSelective(user) == 1 ? true : false;
	}

	@Override
	public boolean updateByPrimaryKeySelective(User user) {
		// TODO Auto-generated method stub
		return userMapper.updateByPrimaryKeySelective(user)==1 ? true :false;
	}
}
